package com.orange.score.activity.entry;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import com.orange.common.util.DateUtil;
import com.orange.score.activity.common.CommonFootballActivity;
import com.orange.score.android.service.ScoreUpdateService;
import com.orange.score.app.ScoreApplication;
import com.orange.score.model.match.MatchManager;
import com.orange.score.model.match.ScoreUpdate;
import com.orange.score.service.MatchService;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class ScoreUpdateActivity extends CommonFootballActivity
{
  protected static final String TAG = "ScoreUpdateActivity";
  ScoreUpdateListAdapter adapter;
  Button clearButton;
  TextView dateTextView;
  Button doneButton;
  Button editButton;
  ListView listView;
  MatchManager matchManager;
  MatchService matchService;
  TextView noMatchTextView;
  ScoreUpdateBroadcastReceiver receiver;
  List<ScoreUpdate> scoreUpdateList;

  public ScoreUpdateActivity()
  {
    this.receiver = new ScoreUpdateBroadcastReceiver(this);
  }

  private void initClearButton()
  {
    this.clearButton = ((Button)findViewById(2131558646));
    this.clearButton.setOnClickListener(new View.OnClickListener(this)
    {
      public void onClick()
      {
        Log.d("ScoreUpdateActivity", "click clear button");
        ScoreUpdateService.clearData();
        ScoreUpdateActivity.access$0(this.this$0);
      }
    });
  }

  private void initDoneButton()
  {
    this.doneButton = ((Button)findViewById(2131558647));
    this.doneButton.setOnClickListener(new View.OnClickListener(this)
    {
      public void onClick()
      {
        Log.d("ScoreUpdateActivity", "click done button");
        this.this$0.adapter.turnOffEditMode();
        ScoreUpdateActivity.access$1(this.this$0);
        ScoreUpdateActivity.access$0(this.this$0);
      }
    });
  }

  private void initEditButton()
  {
    this.editButton = ((Button)findViewById(2131558645));
    this.editButton.setOnClickListener(new View.OnClickListener(this)
    {
      public void onClick()
      {
        Log.d("ScoreUpdateActivity", "click edit button");
        this.this$0.adapter.turnOnEditMode();
        ScoreUpdateActivity.access$1(this.this$0);
        ScoreUpdateActivity.access$0(this.this$0);
      }
    });
  }

  private void initListView()
  {
    this.listView = ((ListView)findViewById(2131558649));
    initializeAdapter();
    this.listView.setAdapter(this.adapter);
    this.listView.setOnScrollListener(new AbsListView.OnScrollListener(this)
    {
      public void onScroll(, int paramInt1, int paramInt2, int paramInt3)
      {
        this.this$0.adapter.onScroll(paramInt1, paramInt2);
      }

      public void onScrollStateChanged(, int paramInt)
      {
      }
    });
  }

  private void initServicesAndManagers()
  {
    ScoreApplication localScoreApplication = (ScoreApplication)getApplication();
    MatchService localMatchService = localScoreApplication.getRealtimeMatchService();
    this.matchService = localScoreApplication.getRealtimeMatchService();
    this.matchManager = localMatchService.getMatchManager();
  }

  private void initializeAdapter()
  {
    this.scoreUpdateList = ScoreUpdateService.getScoreUpdateList();
    this.adapter = new ScoreUpdateListAdapter(this.scoreUpdateList, this);
  }

  private void test()
  {
    ArrayList localArrayList = new ArrayList();
    String[] arrayOfString1 = new String[12];
    arrayOfString1[0] = "664575";
    arrayOfString1[1] = "0";
    arrayOfString1[2] = "20120202163000";
    arrayOfString1[3] = "20120202163000";
    arrayOfString1[4] = "0";
    arrayOfString1[5] = "1";
    arrayOfString1[6] = "1";
    arrayOfString1[7] = "0";
    arrayOfString1[8] = "0";
    arrayOfString1[9] = "0";
    arrayOfString1[10] = "0";
    arrayOfString1[11] = "0";
    String[] arrayOfString2 = new String[12];
    arrayOfString2[0] = "664575";
    arrayOfString2[1] = "0";
    arrayOfString2[2] = "20120202163000";
    arrayOfString2[3] = "20120202163000";
    arrayOfString2[4] = "0";
    arrayOfString2[5] = "0";
    arrayOfString2[6] = "0";
    arrayOfString2[7] = "0";
    arrayOfString2[8] = "1";
    arrayOfString2[9] = "0";
    arrayOfString2[10] = "0";
    arrayOfString2[11] = "0";
    String[] arrayOfString3 = new String[12];
    arrayOfString3[0] = "664575";
    arrayOfString3[1] = "0";
    arrayOfString3[2] = "20120202163000";
    arrayOfString3[3] = "20120202163000";
    arrayOfString3[4] = "0";
    arrayOfString3[5] = "0";
    arrayOfString3[6] = "0";
    arrayOfString3[7] = "0";
    arrayOfString3[8] = "0";
    arrayOfString3[9] = "0";
    arrayOfString3[10] = "0";
    arrayOfString3[11] = "1";
    localArrayList.add(arrayOfString1);
    localArrayList.add(arrayOfString2);
    localArrayList.add(arrayOfString3);
  }

  private void updateButtons()
  {
    if (this.adapter.editMode)
    {
      this.doneButton.setVisibility(0);
      this.clearButton.setVisibility(0);
      this.editButton.setVisibility(8);
      if (this.scoreUpdateList.size() <= 0)
        break label85;
      this.editButton.setEnabled(true);
    }
    while (true)
    {
      while (true)
      {
        return;
        this.doneButton.setVisibility(8);
        this.clearButton.setVisibility(8);
        this.editButton.setVisibility(0);
      }
      label85: this.editButton.setEnabled(false);
    }
  }

  private void updateDateTextView()
  {
    String str = DateUtil.dateToChineseStringByFormat(new Date(), "yyyy年MM月dd日 E").replaceAll("周", "星期");
    this.dateTextView.setText(str);
  }

  private void updateNoMatchTextView()
  {
    if (this.scoreUpdateList.size() > 0)
      this.noMatchTextView.setVisibility(8);
    while (true)
    {
      return;
      this.noMatchTextView.setVisibility(0);
    }
  }

  private void updateScoreUpdateListView()
  {
    this.adapter.updateList(this.scoreUpdateList);
    updateNoMatchTextView();
    updateButtons();
    this.adapter.notifyDataSetChanged();
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903098);
    initServicesAndManagers();
    initListView();
    this.noMatchTextView = ((TextView)findViewById(2131558650));
    updateNoMatchTextView();
    this.dateTextView = ((TextView)findViewById(2131558648));
    initEditButton();
    initClearButton();
    initDoneButton();
    updateButtons();
    registerReceiver();
  }

  public void onDestroy()
  {
    unregisterReceiver(this.receiver);
    super.onDestroy();
  }

  protected void onPause()
  {
    super.onPause();
    ScoreApplication.currentActivity = null;
  }

  public void onRefresh()
  {
    this.matchService.startLiveScoreUpdateTimer(true);
  }

  public void onResume()
  {
    super.onResume();
    updateDateTextView();
    updateScoreUpdateListView();
    ScoreApplication.currentActivity = this;
  }

  public void registerReceiver()
  {
    Log.d("ScoreUpdateActivity", "register score update broadcast receiver");
    IntentFilter localIntentFilter = new IntentFilter("SCORE_UPDATE_BROADCAST");
    registerReceiver(this.receiver, localIntentFilter);
  }

  public class ScoreUpdateBroadcastReceiver extends BroadcastReceiver
  {
    public void onReceive(, Intent paramIntent)
    {
      Log.d("ScoreUpdateActivity", "score update broadcast message received");
      ScoreUpdateActivity.access$0(this.this$0);
    }
  }
}